//
//  YQMessageEditBottomView.m
//  industry
//
//  Created by 王雅强 on 2021/2/1.
//  Copyright © 2021 Haier. All rights reserved.
//

#import "YQMessageEditBottomView.h"

typedef void (^ButtonAction)(void);


@interface YQMessageEditBottomView ()

@property (nonatomic, strong) XLButton * deleteButton;
@property (nonatomic, strong) XLButton * readButton;

@property (nonatomic, copy) ButtonAction delteButtonClickBlock;
@property (nonatomic, copy) ButtonAction readButtonClickBlock;

@end

@implementation YQMessageEditBottomView



#pragma mark - ============== 懒加载 ==============
#pragma mark - ============== 初始化 ==============

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setViewlayer];
        [self addSubview:self.deleteButton];
        [self addSubview:self.readButton];
        
    }
    return self;
}


-(void)setViewlayer{
    
   

    self.layer.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0].CGColor;
    self.layer.shadowColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.04].CGColor;
    self.layer.shadowOffset = CGSizeMake(0,-2);
    self.layer.shadowOpacity = 1;
    self.layer.shadowRadius = 10;
}

-(void)showWithType:(bool)type{
    
    if (!type) {
        [self.deleteButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self);
            make.centerX.equalTo(self).multipliedBy(0.5);

        }];
        [self.readButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self);
            make.centerX.equalTo(self).multipliedBy(1.5);
        }];
    }else{
        [self.deleteButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self);
            make.centerX.equalTo(self);
        }];
        [self.readButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(0, 0));
        }];
    }
    [self.readButton setHidden: type];
    
    
}


-(void)setDelteButtonClickBlock:(void(^)(void))delteButtonClickBlock{
    _delteButtonClickBlock = delteButtonClickBlock;
}
-(void)setReadButtonClickBlock:(void(^)(void))readButtonClickBlock{
    _readButtonClickBlock = readButtonClickBlock;
}

-(void)deleteButtonClick{
    if (self.delteButtonClickBlock) {
        self.delteButtonClickBlock();
    }
}
-(void)readButtonClick{
    if (self.readButtonClickBlock) {
        self.readButtonClickBlock();
    }
}

- (XLButton *)deleteButton
{
    if(!_deleteButton) {
        _deleteButton = ({
            XLButton * deleteButton = [[XLButton alloc] init];
            [deleteButton setBounds:CGRectMake(0, 0, 22, 35)];
            [deleteButton setImage:XLIMAGE(@"delete") forState:UIControlStateNormal];
            [deleteButton setTitle:@"删除" forState:UIControlStateNormal];
            [deleteButton.titleLabel setFont:[UIFont systemFontOfSize:12]];
            [deleteButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [deleteButton verticalImageAndTitle:2];
            [deleteButton addTarget:self action:@selector(deleteButtonClick) forControlEvents:UIControlEventTouchUpInside];
            
            deleteButton;
        });
    }
    return _deleteButton;
}

- (XLButton *)readButton
{
    if(!_readButton) {
        _readButton = ({
            XLButton * readButton = [[XLButton alloc] init];
            [readButton setBounds:CGRectMake(0, 0, 22, 35)];
            [readButton setImage:XLIMAGE(@"read") forState:UIControlStateNormal];
            [readButton setTitle:@"已读" forState:UIControlStateNormal];
            [readButton.titleLabel setFont:[UIFont systemFontOfSize:12]];
            [readButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [readButton verticalImageAndTitle:2];
            [readButton addTarget:self action:@selector(readButtonClick) forControlEvents:UIControlEventTouchUpInside];
            
            readButton;
        });
    }
    return _readButton;
}



 


@end



